package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Dept;
import com.soft.entity.User;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class UserMapperTest {
	@Autowired
	private UserMapper deptMapper;
	@Test
	public void testSelect()
	{
		List<User> deptList = deptMapper.selectList(null);
		for(int i = 0;i < deptList.size();i++)
		{
			System.out.println(deptList.get(i).getId());
			System.out.println(deptList.get(i).getName());
			System.out.println(deptList.get(i).getAge());
			System.out.println(deptList.get(i).getEmail());
		}
	}
	//@Test
	public void testinsert() {
	    User dept = new User();
	    dept.setId(1);
	    dept.setName("Jone");
	    dept.setAge("18");
	    dept.setEmail("test@baomidou.com");
	    deptMapper.insert(dept);
	}
	@Test
	public void updateTest() {
	    User dept = new User();
	    dept.setId(1);
	    dept.setName("aaaa");
	    dept.setAge("aaaa");
	    deptMapper.updateById(dept);
	}
	//@Test
	public void deleteTest() {
	    User dept = new User();
	    dept.setId(2);
	    deptMapper.deleteById(dept);
	}
	@Test
	public void deleteQueryTest() {
		QueryWrapper<User> qw = new QueryWrapper<>();
		qw.eq("name", "王朝");
		deptMapper.delete(qw);
		
		
	}
	@Test
	public void updateQueryTest() {
		UpdateWrapper<User> uw = new UpdateWrapper<>();
		uw.gt("id",3);
		User dept = new User();
		dept.setAge("20");
		int num = deptMapper.update(dept,uw);
		System.out.println(num);
	}
	@Test
	public void selectOneTest() {
		QueryWrapper<User> qw= new QueryWrapper<>();
		qw.gt("id", 1);
		try {
			User dept = deptMapper.selectOne(qw);
			System.out.println(dept);
			
		}catch(Exception e) {
			System.out.println("沉默不是代表我的错");
		}
	}
}